﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using FluentNHibernate.Mapping;

namespace Tanmia.NHibernate.Mapping
{
    public class InvoiceMap : ClassMap<Invoice>
    {
        public InvoiceMap()
        {
            Table("Invoice");

            Id(x => x.InvoiceID).Not.Nullable().GeneratedBy.Identity();

            Map(x => x.InvoiceType).Not.Nullable().CustomType<InvoiceTypeEnum>();
            Map(x => x.PaymentMethod).Not.Nullable().CustomType<PaymentMethodEnum>();
            //Map(x => x.Total).Not.Nullable().Default("0");
            Map(x => x.Discount).Not.Nullable().Default("0");
            //Map(x => x.Final).Not.Nullable().Default("0");
            Map(x => x.CreateDate).Not.Nullable().Not.Update();
            Map(x => x.Note).Length(2048).Nullable();

            HasMany(x => x.Details).KeyColumn("InvoiceID").Cascade.SaveUpdate();

            References(x => x.User, "UserID").Not.Nullable();
            References(x => x.Person, "PersonID").Not.Nullable();
            References(x => x.Repository, "RepositoryID").Not.Nullable();
        }
    }
}
